

***************************************************************************************
*FIGURE 1, PANEL A: ACCUMULATION OF ALL PATENTS FOR BAYH DOLE GRANTS (10 YEARS) VS. ACCUMULATION OF CITATION LINKED PATENTS 
***************************************************************************************

*CITATION LINKED MATCHES
use replicationfile_main_citation_linked, clear
collapse trunc_haspat_corp , by(yearsout)
ren trunc_haspat_corp trunc_haspat_corp_dir

foreach var of varlist trunc* {
replace `var'=`var'*100
}

gen const=1
reshape wide trunc_haspat_corp_dir, i(yearsout) j(const)
save temp, replace

*DIRECT (BAYH DOLE) MATCHES
use replicationfile_main_direct_linked, clear
tab trunc_haspat_any
sort full_grant_num yearsout 
collapse trunc_haspat_any, by(yearsout)
ren trunc_haspat_any trunc_haspat_any_bd
foreach var of varlist trunc* {
replace `var'=`var'*100
}
gen const=1
reshape wide trunc_haspat_any_bd, i(yearsout) j(const)
merge 1:1 yearsout using temp

line trunc_haspat_corp_dir1 trunc_haspat_any_bd1 yearsout, ytitle("% of grants linked to at least one patent") xtitle("Years after grant approval") title("All Patents") legend(pos(6) label(1 "Indirect Citation Link") label(2 "Direct Acknowledgment")) scale(.8) scheme(s2mono) saving(patentlag_bd_dir, replace)

***************************************************************************************
*FIGURE 1, PANEL B: ACCUMULATION OF FDA PATENTS FOR BAYH DOLE GRANTS (10 YEARS) VS. ACCUMULATION OF CITATION LINKED PATENTS 
***************************************************************************************

*CITATION LINKED MATCHES
use replicationfile_main_citation_linked, clear

collapse trunc_haspat_fda, by(yearsout)
ren trunc_haspat_fda trunc_haspat_fda_dir

foreach var of varlist trunc* {
replace `var'=`var'*100
}
gen const=1
reshape wide trunc_haspat_fda_dir, i(yearsout) j(const)
save temp, replace


*DIRECT (BAYH DOLE) MATCHES
use replicationfile_main_direct_linked, clear
tab trunc_haspat_fda
sort full_grant_num yearsout 

collapse trunc_haspat_fda, by(yearsout)
ren trunc_haspat_fda trunc_haspat_fda_bd
foreach var of varlist trunc* {
replace `var'=`var'*100
}
gen const=1
reshape wide trunc_haspat_fda_bd, i(yearsout) j(const)
merge 1:1 yearsout using temp

line trunc_haspat_fda_dir1 trunc_haspat_fda_bd1 yearsout, ytitle("% of grants with a patent, FDA") xtitle("Years after grant approval") title("FDA Approved") legend(pos(6) label(1 "Indirect Citation Link") label(2 "Direct Acknowledgment")) scale(.8) scheme(s2mono) saving(patentlag_bd_dir_fda, replace)

graph combine patentlag_bd_dir.gph patentlag_bd_dir_fda.gph, cols(2) ysize(3.5) xsize(7) altshrink scale(.8)
graph export Figure1_patentlag_dir_indir.pdf, replace


***************************************************************************************
*FIGURE 2: ACCUMULATION OF CITATION LINKED PATENTS 
***************************************************************************************

*********************PANEL A AND B: DISEASE TARGETTED VS. NOT

use replicationfile_main_citation_linked, clear
collapse trunc_haspat_fda trunc_haspat_corp, by(yearsout disease)
foreach var of varlist trunc_haspat* {
replace `var'=`var'*100
}
reshape wide trunc_haspat_corp trunc_haspat_fda, i(yearsout) j(disease)

*ALL PATENTS
line trunc_haspat_corp1 trunc_haspat_corp0 yearsout, ytitle("% of grants w/ publications cited by a patent") subtitle("All Patents") xtitle("Years after grant approval") legend(label(1 "Disease Targeted") label(2 "Not Disease Targeted") size(small)) scale(.8) legend(col(4)) saving(patentlag_corp_disease, replace) scheme(s2mono)
graph export patentlag_corp_disease.pdf, replace

*FDA APPROVED 
line trunc_haspat_fda1 trunc_haspat_fda0 yearsout, ytitle("% of grants w/ publications cited by a patent") subtitle( "FDA Approved") xtitle("Years after grant approval") legend(label(1 "Disease Targeted") label(2 "Not Disease Targeted") size(small)) scale(.8) legend(col(4)) saving(patentlag_fda_disease, replace) scheme(s2mono)
graph export patentlag_fda_disease.pdf, replace

*********************PANEL C AND D: HUMAN ORIENTED VS. NOT

use replicationfile_main_citation_linked, clear
collapse trunc_haspat_corp trunc_haspat_fda, by(yearsout human)
foreach var of varlist trunc_haspat* {
replace `var'=`var'*100
}

reshape wide trunc_haspat_corp trunc_haspat_fda, i(yearsout) j(human)

*ALL
line trunc_haspat_corp1 trunc_haspat_corp0 yearsout, ytitle("% of grants w/ publications cited by a patent") subtitle("All Patents") xtitle("Years after grant approval") legend(label(1 "Patient Oriented") label(2 "Not Patient Oriented") size(small)) scale(.8) legend(col(4)) saving(patentlag_corp_human, replace) scheme(s2mono)
graph export patentlag_corp_human.pdf, replace

*FDA
line trunc_haspat_fda1 trunc_haspat_fda0 yearsout, ytitle("% of grants w/ publications cited by a patent") subtitle( "FDA Approved") xtitle("Years after grant approval") legend(label(1 "Patient Oriented") label(2 "Not Patient Oriented") size(small)) scale(.8) legend(col(4))  saving(patentlag_fda_human, replace) scheme(s2mono)
graph export patentlag_fda_human.pdf, replace

*********************PANEL E AND F: RFA VS NOT

use replicationfile_main_citation_linked, clear
drop if rfa==.
collapse trunc_haspat_fda trunc_haspat_corp, by(yearsout rfa)
foreach var of varlist trunc_haspat* {
replace `var'=`var'*100
}

reshape wide trunc_haspat_corp trunc_haspat_fda, i(yearsout) j(rfa)

*ALL
line trunc_haspat_corp1 trunc_haspat_corp0 yearsout, ytitle("% of grants w/ publications cited by a patent") subtitle("All Patents") xtitle("Years after grant approval") legend(label(1 "RFA") label(2 "Non RFA") size(small)) scale(.8) legend(col(4)) saving(patentlag_corp_rfa, replace) scheme(s2mono)
graph export patentlag_corp_rfa.pdf, replace

*FDA
line trunc_haspat_fda1 trunc_haspat_fda0 yearsout, ytitle("% of grants w/ publications cited by a patent") subtitle( "FDA Approved") xtitle("Years after grant approval") legend(label(1 "RFA") label(2 "Non RFA") size(small)) scale(.8) legend(col(4)) saving(patentlag_fda_rfa, replace) scheme(s2mono)
graph export patentlag_fda_rfa.pdf, replace


*COMBINE SEPARATE FIGURES TO OBTAIN FIGURE 2 FROM PAPER: 
graph combine patentlag_corp_disease.gph patentlag_fda_disease.gph patentlag_corp_human.gph patentlag_fda_human.gph patentlag_corp_rfa.gph patentlag_fda_rfa.gph, cols(2) ysize(9) xsize(7) altshrink  saving(patentlag_all, replace)
graph export Figure2_patentlag_dir_all.pdf, replace


***************************************************************************************
*FIGURE 3: PERCENT WITH PATENT OR DRUG, BY TYPE OF ORGANISM
***************************************************************************************

use replicationfile_main_citation_linked, clear
keep if disease==0
collapse trunc_haspat_fda trunc_haspat_corp, by(yearsout type_of_orgnsm)
foreach var of varlist trunc_haspat* {
replace `var'=`var'*100
}
keep if yearsout==25
gen id=1

label var trunc_haspat_corp "Any Private Sector Patent"
label var trunc_haspat_fda "FDA Approved" 
label define yearsout 25 "25 years"
label values yearsout yearsout

gen catorder=. 
replace catorder = 1 if type_of_orgnsm=="human"
replace catorder = 2 if type_of_orgnsm=="primates"
replace catorder = 3 if type_of_orgnsm=="other mammals"
replace catorder = 4 if type_of_orgnsm=="rodents"
replace catorder = 5 if type_of_orgnsm=="vertebrates"
replace catorder = 6 if type_of_orgnsm=="invertebrates"
replace catorder = 7 if type_of_orgnsm=="eukaryote, multicellular"
replace catorder = 8 if type_of_orgnsm=="eukaryote, unicellular"
replace catorder = 9 if type_of_orgnsm=="prokaryote"
replace catorder = 10 if type_of_orgnsm=="virus"
replace catorder = 11 if type_of_orgnsm=="undefined"

drop if catorder== 11

*CREATES TOP PANEL: ALL PATENTS
graph hbar trunc_haspat_corp, over(type_of_orgnsm, sort(catorder)) blabel(type_of_orgnsm, pos(base) color(bg)) ytitle("% grants with publications cited by at least one patent, up to 25 years later") saving(fig_corp, replace) scheme(s2mono)

*CREATES BOTTOM PANEL: FDA RELATED PATENTS
graph hbar trunc_haspat_fda, over(type_of_orgnsm, sort(catorder)) blabel(type_of_orgnsm, pos(base) color(bg)) ytitle("% grants with publications cited by at least one patent associated with an FDA approved drug, up to 25 years later") saving(fig_fda, replace) scheme(s2mono) 


*COMBINE SEPARATE FIGURES TO OBTAIN FIGURE 3 FROM PAPER: 
graph combine fig_corp.gph fig_fda.gph, ycommon cols(1) title("Follow-on Patenting by Organismic Complexity") subtitle("Non-disease oriented grants only") graphregion(color(white)) scale(.7) ysize(5) xsize(6) altshrink saving(fig_organism, replace)
graph export Figure3_organism.pdf, replace


********************************************************************************
*CREATE FILES FOR TABLE A1: GRANT LEVEL SUMMARY
********************************************************************************

use replicationfile_tableA1, clear

*SAMPLE COVERAGE
codebook full_grant_num
codebook full_grant_num if np_0to10_all_name_bd>0 & np_0to10_all_name_bd!=.
codebook full_grant_num if np_ackmatch_dir_corp_p5>0 & np_ackmatch_dir_corp_p5!=.

*GRANT CHARAC
gen r01equiv=(activity=="R01" | activity=="R23" | activity=="R29" | activity=="R37")
gen primate=(type_of_orgnsm=="primates")
gen othmammal=(type_of_orgnsm=="other mammals")
gen rodent=(type_of_orgnsm=="rodents")
gen vertebrates=(type_of_orgnsm=="vertebrates")
gen invertebrates=(type_of_orgnsm=="invertebrates")
gen eukaryotemulti=(type_of_orgnsm=="eukaryote, multicellular")
gen eukaryoteuni=(type_of_orgnsm=="eukaryote, unicellular")
gen prokaryote=(type_of_orgnsm=="prokaryote")
gen virus=(type_of_orgnsm=="virus")
gen undefined=(type_of_orgnsm=="undefined")

foreach charac of varlist r01equiv rfa disease human primate othmammal rodent vertebrates invertebrates eukaryotemulti eukaryoteuni prokaryote virus undefined {
di "SUMMARY FOR `charac'"
sum `charac'
sum `charac' if np_0to10_all_name_bd>0 & np_0to10_all_name_bd!=.
sum `charac' if np_ackmatch_dir_corp_p5>0 & np_ackmatch_dir_corp_p5!=.
}

********************************************************************************
*CREATE FILES FOR TABLE G2: GRANT LEVEL SUMMARY
********************************************************************************

use replicationfile_tableG2, clear
gen years_at_risk=ptnt_year_all-fy
expand years_at_risk+1
bysort appl_id: gen year=fy+_n-1
gen di=year==ptnt_year_all
replace di=0 if ptnt_year_all==2013

logistic di disease human diseaseXhuman rfa i.orgnsm_type new_grant mp_grants r01_grants oth_grants ln_amnt i.IC i.fy, vce(cluster appl_id)
estimates save all_patents.ster, replace

use replicationfile_tableG2, clear
drop if ptnt_year_allbd<2013
gen years_at_risk=ptnt_year_allnbd-fy
expand years_at_risk+1
bysort appl_id: gen year=fy+_n-1
gen di=year==ptnt_year_allnbd
replace di=0 if ptnt_year_allnbd==2013

logistic di disease human diseaseXhuman rfa i.orgnsm_type new_grant mp_grants r01_grants oth_grants ln_amnt i.IC i.fy, vce(cluster appl_id)
estimates save nbd_patents.ster, replace

use replicationfile_tableG2, clear
drop if ptnt_year_pub<2013 & ptnt_year_corp==2013
gen years_at_risk=ptnt_year_corp-fy
expand years_at_risk+1
bysort appl_id: gen year=fy+_n-1
gen di=year==ptnt_year_corp
replace di=0 if ptnt_year_corp==2013

logistic di disease human diseaseXhuman rfa i.orgnsm_type new_grant mp_grants r01_grants oth_grants ln_amnt i.IC i.fy, vce(cluster appl_id)
estimates save corp_patents.ster, replace

use replicationfile_tableG2, clear
gen years_at_risk=ptnt_year_fda-fy
expand years_at_risk+1
bysort appl_id: gen year=fy+_n-1
gen di=year==ptnt_year_fda
replace di=0 if ptnt_year_fda==2013

logistic di disease human diseaseXhuman rfa i.orgnsm_type new_grant mp_grants r01_grants oth_grants ln_amnt i.IC i.fy, vce(cluster appl_id)
estimates save fda_patents.ster, replace

use replicationfile_tableG2, clear

set emptycells drop
set matsize 10000
estimates drop _all

estimates use all_patents.ster
eststo
estimates use nbd_patents.ster
eststo
estimates use corp_patents.ster
eststo
estimates use fda_patents.ster
eststo

esttab *, keep(disease human diseaseXhuman rfa new_grant mp_grants r01_grants oth_grants ln_amnt) varwidth(25) nonumber noobs nogaps nodep eform label b(%5.3f) se(%5.3f) compress scalars("N_clust Nb. of Grant Applications" "N Nb. of Observations" "r2_p Adjusted R2") sfmt(%10.0fc %10.0fc %9.3f) mlabels("All Patents" "Excluding Bayh-Dole Patents" "Excluding Patents with Non-corporate Assignees" "Patents Associated with an FDA-approved Drug") eqlabels(none) addnotes("Estimates from logistic specifications. All models incorporate a full suite of application year effects, funding institute effects, grant type effects, and organism type effects. Displayed estimates correspond to exponentiated coefficients. For example, the estimates in the first column imply that disease-oriented grants are 14.8% more likely than non-disease, non-patient-oriented grants to be associated with a patent.")
esttab * using table_g2.rtf, keep(disease human diseaseXhuman rfa new_grant mp_grants r01_grants oth_grants ln_amnt) varwidth(25) nonumber noobs nogaps nodep eform label b(%5.3f) se(%5.3f) compress scalars("N_clust Nb. of Grant Applications" "N Nb. of Obs." "r2_p Adjusted R2") sfmt(%10.0fc %10.0fc %9.3f) mlabels("All Patents" "Excluding Bayh-Dole Patents" "Excluding Patents with Non-corporate Assignees" "Patents Associated with an FDA-approved Drug") eqlabels(none) addnotes("Estimates from logistic specifications. All models incorporate a full suite of application year effects, funding institute effects, grant type effects, and organism type effects. Displayed estimates correspond to exponentiated coefficients. For example, the estimates in the first column imply that disease-oriented grants are 14.8% more likely than non-disease, non-patient-oriented grants to be associated with a patent.") replace


